﻿/*

Copyright 2009 Guillaume Amringer

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

package utils {

	public class SexUtils {
		
		public static var binary_prefixes:Array = new Array('', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi');
		public static var decimal_prefixes:Array = new Array('', 'k', 'm', 'G', 'T', 'P', 'E', 'Z', 'Y');
		
		public function SexUtils():void {
			
		}
		
		public static function units(pValue:Number, pExt:String, pBinary:Boolean = true):String {
			var c:int = 0;
			
			if(pBinary){
				while(pValue >= 1024){
					pValue /= 1024;
					c++;
				}
			
				return pValue.toFixed(2) + ' ' + binary_prefixes[c] + pExt;
			}else {
				while(pValue >= 1000){
					pValue /= 1000;
					c++;
				}
			
				return pValue.toFixed(2) + ' ' + binary_prefixes[c] + pExt;
			}
		}
	}
}